<?php

namespace App\Http\Requests\Admin\Customer;

use App\Http\Requests\ApiRequest;
use App\Models\Panx\Sex;
use App\Services\Locale\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property string role_name
 * @property string email
 */
class StaffUpdateRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $admin_id = last(explode('/', $this->Url())); // same as last($this->segments())

        $data = [
            'name'      => ['required', 'string', 'max:'.self::MAX_STRING],
            'email'     => 'required|email|unique:customer_admins,email,'.$admin_id,
            'account'   => ['required', 'string', 'max:'.self::MAX_STRING, Rule::unique('customer_admins', 'account')->ignore($admin_id)],
            'password'  => 'nullable|string|min:6|max:'.self::MAX_STRING,
            'sex'       => ['required', 'int', Rule::in(Sex::allIds())],
//            'born_at'   => 'nullable|date',
            'role_name' => 'nullable|string|max:'.self::MAX_STRING,
            'phone'     => ['required', 'string', 'max:'.self::MAX_STRING],
        ];

        return $data;
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.*'      => '名称是必须填',
//            'email.*'     => '邮箱未填写或格式不合法或已经重复',
//            'account.*'   => '账号已注册，请尝试其他账号',
//            'password.*'  => '密码长度必须6个字符',
//            'phone.*'     => '电话必须是合法手机号',
//            'sex.*'       => '性别必须是男和女',
//            'role_name.*' => '管理员角色必须是字符串',
//            'born_at.*'   => '无效的生日日期，或日期格式错误',
//
//        ];
//    }

}
